/***************************************************************************
 *   Copyright (C) 2007 by Grzegorz Latarowski, Maciej Gajewski            *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
 
 
#ifndef GAUTOCLIENT_H
#define GAUTOCLIENT_H


#include <QPixmap>


// gnet
#include "gnetclient.h"
#include "gnetudp.h"

// libautonet
#include "autopackets.h"

// libanalyzer
#include "analyzer.h"    // for pimage_t 


#define UDP_PORT  34444
#define AUTO_PORT 5102



// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
class GAutoClient : public GNetClient
{
	Q_OBJECT
			
public:

	// construction/destruction
	GAutoClient( QObject * pParent = 0 );
	virtual ~GAutoClient();

	// general
	
	/// Extends GNetClient's disconnect method
	virtual void disconnectFromHost();

	// --- Camera Specific ---
	
	/// Returns next frame
	QPixmap frame();
	
	/// Returns params from camera.
	GParams params();

	/// Returns byteArray containg camera Config file
	QByteArray cameraConfig();

	/// Returns byteArray containing Ares config file
	QByteArray areasConfig();
			
	/// Sends Ares config file to server.
	void sendAreasConfig( QByteArray & fileData );
	
	/// Sends markers analyzer image to server.
	void sendMarkersImage( pimage_t markersImage );
	
	/// Sends roi analyzer image to server.
	void sendRoiImage( pimage_t roiImage );
	
	/// Sends shutter analyzer image to server.
	void sendShutterImage( pimage_t shutterImage );
	
	/// Sends params to server.
	void sendParams( const GParams & params );

	/// Stops receiving frames via udp
	void stopReceiving();
	/// Starts receiving frames via udp
	void startReceiving();
	
	
	// ====================================================
	// packets processing
	
	void processPacket( GNetPacket * pPacket );
	
	void process_PACKET_OBJECTS_COORDINATES( GAutoObjectCoordinates * pPacket );
	void process_PACKET_FRAME( GAutoFrame * pPacket );
	void process_PACKET_EVENT_TRIGGER( GAutoEventTrigger * pEventTrigger );

public slots:
	/// Processes received packet.
	void udpPacketsReceived( const QQueue< QPair<quint16, QByteArray> >& packets );
	
signals:
	void newObjectsCoordinates( QList<objectCoordinates> & );
	void newPixmap( const QPixmap & );
	void reportObject( const QString & message, bool highlighted );
	void accelExceeded();
	
private:
	GUdpReceiver _udpReceiver;  ///< listens on udp for samples

}; // class !GAutoClient
// ---------------------------------------------------------------------------



#endif // !GAUTOCLIENT_H

// eof
